<?php
/**
 * @authors alex (20779512@qq.com)
 * @date    2014-03-24 17:25:39
 * @version 1.0
 */

class SubmitAction extends HomeAction {

    public function index(){
        $map['id']=$this->_user['memberID'];
        $yongjin = M('Member')->where($map)->getField('money');
        $this->assign('yongjin',$yongjin);
        $this->display();
    } 


    public function save(){  
    	$obj = D('Tixian');
    	if ($data = $obj->create()) {
            $map['id']=$this->_user['memberID'];
            $oldMoney = M('Member')->where($map)->getField('money');

            if ($data['money'] > $oldMoney) {
                $state = '您可提现佣金不足'.$data['money'].'元';
                echo $this->echo_json_str($state,$message,$url); die;
            }

            if ($data['money'] < C('tx_min')) {
                $state = '提现金额不能小于'.C('tx_min').'元';
                echo $this->echo_json_str($state,$message,$url); die;
            }

            $newMoney = $oldMoney - $data['money'];

            //用户账号减去佣金
            M('Member')->where($map)->setDec('money',$data['money']); 

            $data['oldMoney'] = $oldMoney;
            $data['newMoney'] = $newMoney;

    		if ($obj->add($data)) {
                $state = 'SUCCESS';
                $message = '提现申请成功';
                $url = U('Submit/history');
    		}else{
                $state = '操作失败';
    		}
    	}else{
    		$state =$obj->getError();
    	}
        echo $this->echo_json_str($state,$message,$url); 
    }


    public function history(){
        $map['memberID'] = $this->_user['memberID'];
        $list = M('Tixian')->where($map)->order('id desc')->select();
        $this->assign('list',$list);
        $this->display();
    }

    
}